/**
 * all 练习
 * 需求:
 *   读取 resource/1.html   2.html   3.html  文件内容, 然后合并输出
 */

// const fs = require("fs");

//读取
// fs.readFile("./resource/1.html", (err, data1) => {
//   if (err) throw err;
//   fs.readFile("./resource/2.html", (err, data2) => {
//     if (err) throw err;
//     fs.readFile("./resource/3.html", (err, data3) => {
//       if (err) throw err;
//       console.log(data1.toString() + data2.toString() + data3.toString());
//     });
//   });
// });

// promise
const fs = require('fs/promises');

let p1 = fs.readFile('./resource/1.html');
let p2 = fs.readFile('./resource/2.html');
let p3 = fs.readFile('./resource/3.html');

let result = Promise.all([p1, p2, p3]);

result.then(data => {
  console.log(data.map(item => item.toString()).join(''));
}, error => {
  console.log(error);
})